home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / UGetMultipleFiles 1.4 / LFSSpecArrayComp.cp < prev    next >
Encoding:
Text File  |  1997-03-06  |  2.0 KB  |  63 lines  |  [TEXT/CWIE]

  1. // --------------------------------------------------------------------------------------------
  2. //    UGetMulltipleFiles - An Add Files utility class
  3. //        By David Hirsch
  4. // --------------------------------------------------------------------------------------------
  5.  
  6. // --------------------------------------------------------------------------------------------
  7. // LFSSpecArrayComp - This is an array comparator for an LArray of FSSpec records.
  8. //        It compares on the basis of volume, directory and name, so you can add
  9. //        multiple files with identical names in different directories
  10. // --------------------------------------------------------------------------------------------
  11.  
  12. #include "LFSSpecArrayComp.h"
  13. #include <string.h>
  14.  
  15. Int32
  16. LFSSpecArrayComp::Compare(
  17.     const void*        inItemOne,
  18.     const void*        inItemTwo,
  19.     Uint32            /* inSizeOne */,
  20.     Uint32            /* inSizeTwo */) const
  21. {
  22.     FSSpec fs1;
  23.     FSSpec fs2;
  24.     
  25.     fs1 = *((FSSpec *) inItemOne);
  26.     fs2 = *((FSSpec *) inItemTwo);
  27.     if (fs1.vRefNum != fs2.vRefNum) {
  28.         return (fs1.vRefNum - fs2.vRefNum);
  29.     } else {            // volumes are the same
  30.         if (fs1.parID != fs2.parID)    {
  31.             return (fs1.parID - fs2.parID);
  32.         } else {        // directories are the same
  33.             if (fs1.name != fs2.name) {
  34.                 return ::StringOrder(fs1.name, fs2.name, smSystemScript, smSystemScript,
  35.                                     systemCurLang, systemCurLang);    // we use the system's alphabetizing
  36.                                                                     // algorithm so the added list will
  37.                                                                     // have the same order as the SF list
  38.             } else {    // everything's the same
  39.                 return 0;
  40.             }
  41.         }
  42.     }
  43.     return 0;    // we'll never get here; just so compiler won't complain
  44. }
  45.  
  46. Boolean
  47. LFSSpecArrayComp::IsEqualTo(
  48.     const void*        inItemOne,
  49.     const void*        inItemTwo,
  50.     Uint32            /* inSizeOne */,
  51.     Uint32            /* inSizeTwo */) const
  52. {
  53.     FSSpec fs1;
  54.     FSSpec fs2;
  55.     fs1 = *((FSSpec *) inItemOne);
  56.     fs2 = *((FSSpec *) inItemTwo);
  57.     LStr255 name1(fs1.name);
  58.     LStr255 name2(fs2.name);
  59.     if ((fs1.vRefNum == fs2.vRefNum) && (fs1.parID == fs2.parID) && (name1.CompareTo(name2) == 0))
  60.         return true;
  61.     return false;
  62. }
  63.